class Contact < ActiveRecord::Base
  validates_presence_of :forename
  validates_presence_of :surname
  validates_presence_of :email
  validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
  
  def name
    self.forename + " " + self.surname
  end
  
  def self.search(query)
    query = "%#{query}%"
    Contact.find(:all, :conditions => ['forename LIKE ? OR surname LIKE ? OR email LIKE ? OR phone LIKE ?', query, query, query, query])
  end
end